import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    go_card_url: '', // 开会员地址
    time: '',
    sort_by: {
      sort_by: ''
    },
    city: '上海',
    value: '',
    lat: '31.2303904',
    lng: '121.4737021'
  },
  mutations: {
    reset(state) {
      if (state.sort_by.sort_by == '' && state.time == '') return
      state.sort_by.sort_by = ''
      state.time = ''
    },
    toggleSortBy(state, val) {
      state.sort_by.sort_by = val
    },
    toggleTime(state, val) {
      state.time = val
    },
    savePlusUrl(state, url) {
      if (state.go_card_url == url) return
      state.go_card_url = url
    },
    setCity(state, cityInfo) {
      state.city = cityInfo.name
      state.lat = cityInfo.lat
      state.lng = cityInfo.lng
    },
    setValue(state, value) {
      console.log(state)
      state.value = value
      console.log(state)
    }
  }
})
